package com.mk.base.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.mk.base.model.request.PageRequest;
import com.mk.base.model.response.RspPage;

/**
 * Created by Hao on 2017-03-24.
 */
public abstract class BaseController {

    protected <T> Page getPagination(PageRequest pageRequest) {
        Page<T> page =  new Page<T>(pageRequest.getPage(), pageRequest.getRows());
        page.setAsc("asc".equalsIgnoreCase(pageRequest.getOrder()));//升序 降序
        page.setOrderByField(pageRequest.getSort());//排序字段名称
        return page;
    }

    protected <T> RspPage convertSuccessPage(Page<T> page){
        return RspPage.SUCCESS(page.getCurrent(),page.getPages(),page.getSize(),page.getTotal(),page.getRecords());
    }

    protected RspPage convertErrorPage(String error){
        return RspPage.ERROR(error);
    }
}
